package com.z.pms1.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.z.pms1.dao.MenuDao;
import com.z.pms1.model.C_menu;

@Repository("menuDao")
public class MenuDaoImpl implements MenuDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	@Transactional(readOnly=true)
	@SuppressWarnings("unchecked")
	public List<C_menu> allMenuList() {
		//Session session = sessionFactory.openSession();
		Query query = getSession().createQuery("FROM C_menu m ORDER BY m.display_seq");
		List<C_menu> c_menuList = (List<C_menu>) query.list();
		//session.close();
		return c_menuList;
	}
	
	public C_menu get(String id) {
		return (C_menu) getSession().get(C_menu.class, id);
	}
	
	protected Session getSession() {
		return sessionFactory.getCurrentSession();
	}

}
